package metastructure;

/**
 * 单链表.
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {};

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    /**
     * 打印整个单链表.
     */
    public void show() {
        if (this == null) {
            System.out.println("Empty LinkedList!");
            return;
        }

        StringBuilder str = new StringBuilder();
        ListNode tmp = this;
        str.append(this.val);
        while (tmp.next != null) {
            str.append("->");
            str.append(tmp.next.val);
            tmp = tmp.next;
        }
        System.out.println(str.toString());
    }
}
